-
Notifications
You must be signed in to change notification settings - Fork 396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: a global hook for OpenSumi DevTools to communicate with #1560
Conversation
不能像sendRequest和sendNotification这么来
Codecov Report
@@ Coverage Diff @@
## main #1560 +/- ##
==========================================
- Coverage 57.87% 57.66% -0.21%
==========================================
Files 1251 1252 +1
Lines 77996 78146 +150
Branches 16275 16319 +44
==========================================
- Hits 45139 45062 -77
- Misses 29919 30124 +205
- Partials 2938 2960 +22
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
对于Web端,只要浏览器安装了opensumi devtools插件即可生效;对于Electron端,需要等该插件上架到chrome webstore后再利用electron-devtools-installer进行集成(见此issue)。 所以不想分好几个PR的话,可以等到插件发布上架后再合并这个PR。 |
6b19cb4
to
29ff670
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR will resolve #1098. You are welcomed to visit the issue to review the whole process of how the devtools developed.
Types
Background or solution
A global hook
Step 1. opensumi/core exposes a global hook
window.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__ = {}
when ClientApp starts.Step 2. opensumi-devtools tries to detect the existence of the hook, if the hook exists it will run.
Step 3. if users click "startCapture" button in the devtools, a few variables and functions will be injected to the hook by the API
chrome.devtools.inspectedWindow.eval()
.Step 4. when messages are received and sended in proxy.ts, opensumi/core will try to access to
window.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__.capture
, if accessible, it will call the injected global capture function and then put messages towindow.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__.messages
.Step 5. opensumi-devtools get new messages from
window.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__.messages
every 1 second and set the message array to empty after getting all new messages.Step 6. opensumi-devtools present the messages with a good UI.
Step 7. if users click "stopCapture" button,
window.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__
will be set to{}
so no capture function can be accessed and opensumi/core will stop sharing its messages.A contribution point
Step 1. by leveraging opensumi's lifecycle contribution, I set an event listener
window.addEventListener('devtools:latency', ()=>{...})
in initialize phase.Step 2. if users click
startCapture
button, the custom event "devtools:latency" with "start" command will be dispatched. opensumi/core will start to test rtt after receiving the event and put the value towindow.__OPENSUMI_DEVTOOLS_GLOBAL_HOOK__.latency
.Step 3. opensumi-devtools will get
latency
value from the hook and presents it in UI.Changelog
a global hook and a contribution point for OpenSumi DevTools to communicate with.